#include "headfiles.h"

using namespace std;

int main(int argc, char **argv) {
    if (argc != 2) {
        cout << "Usage: " << argv[0] << " file" << endl;
        return 0;
    }

    fstream fs;
    fs.open(argv[1], iostream::in);
    if (!fs.is_open()) {
        cout << "File " << argv[1] << " open error!" << endl;
        return 1;
    }

    string str;
    vector<int> vec;
    while (fs >> str) {
        if (str.empty()) {
            break;
        }
        int val = atoi(str.c_str());
        vec.push_back(val);
    }
    fs.close();

    int n = vec.size();
    int *ar = new int[n];
    if (ar == NULL) {
        cout << "Allocate array error!" << endl;
        return 1;
    }

    int i;
    for (i = 0; i < n; i++) {
        ar[i] = vec[i];
    }

    int res_i, res_j, res_k;
    bool res;
    res = calc3OrderedNumbers(ar, n, res_i, res_j, res_k);
    if (res) {
        cout << "(" << res_i << ", " << ar[res_i] << ")" << endl;
        cout << "(" << res_j << ", " << ar[res_j] << ")" << endl;
        cout << "(" << res_k << ", " << ar[res_k] << ")" << endl;
    }
    else {
        cout << "Cannot find the three numbers!" << endl;
    }

    return 0;
}

